package com.amap.demo.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amap.demo.view.util.Constants;

import butterknife.Bind;
import butterknife.ButterKnife;
import jacksen.cluster.ClusterOverlay;

/**
 * 地图聚合
 *
 * @author ys
 */
public class MarkersClusterActivity extends AppCompatActivity {

    @Bind(R.id.mapView)
    MapView mapView;
    private AMap aMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_markers_cluster);
        ButterKnife.bind(this);

        mapView.onCreate(savedInstanceState);
        aMap = mapView.getMap();
        aMap.setOnMapLoadedListener(new AMap.OnMapLoadedListener() {
            @Override
            public void onMapLoaded() {
                ClusterOverlay clusterOverlay = new ClusterOverlay(MarkersClusterActivity.this, aMap);
                for (int i = 0; i < Constants.cityLatLngs.length; i++) {
                    ClusterItem clusterItem = new ClusterItem(Constants.cityNames[i], Constants.cityLatLngs[i]);
                    clusterOverlay.addClusterItem(clusterItem);
                }
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }
}
